home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / AmiTCP30b2.lha / src / amitcp / kern / accesscontrol.c next >
C/C++ Source or Header  |  1994-04-06  |  2KB  |  63 lines

  1. RCS_ID_C="$Id: accesscontrol.c,v 3.2 1994/04/06 15:36:50 too Exp $";
  2. /*
  3.  * Copyright (c) 1993, 1994    AmiTCP/IP Group, <amitcp-group@hut.fi>,
  4.  *                            Helsinki University of Technology, Finland.
  5.  *                            All rights reserved.
  6.  *
  7.  * Created: Tue Mar 22 22:24:17 1994 too
  8.  * Last modified: Wed Apr  6 18:36:22 1994 too
  9.  *
  10.  * HISTORY
  11.  * $Log: accesscontrol.c,v $
  12.  * Revision 3.2  1994/04/06  15:36:50  too
  13.  * Added checking for private ports
  14.  *
  15.  * Revision 3.1  1994/03/26  09:37:18  too
  16.  * Initial relelase
  17.  */
  18.  
  19. #include <exec/types.h>
  20.  
  21. #include <sys/systm.h>
  22. #include <sys/malloc.h>
  23. #include <kern/amiga_config.h>
  24. #include <kern/amiga_netdb.h>
  25. #include <kern/accesscontrol.h>
  26.  
  27. #include <sys/syslog.h>
  28.  
  29. int controlaccess(struct in_addr shost, unsigned short dport)
  30. {
  31.   int i;
  32.  
  33.   LOCK_R_NDB(NDB);        
  34.   for (i = 0; NDB->ndb_AccessTable[i].ai_flags; i++) 
  35. #define AT NDB->ndb_AccessTable[i]
  36. #define host (*(ULONG *)&shost)                /* XXX */
  37.     if ((AT.ai_port == 0 && (!(AT.ai_flags & ACF_PRIVONLY) || dport < 1024)
  38.      || AT.ai_port == dport) &&
  39.     ((host ^ AT.ai_host) & AT.ai_mask) == 0) {
  40.       /*
  41.        * match
  42.        */
  43.       int allow = AT.ai_flags & ACF_ALLOW;
  44.  
  45.       if (AT.ai_flags & ACF_LOG)
  46.     log(allow? LOG_INFO: LOG_NOTICE,
  47.         "Access from host %ld.%ld.%ld.%ld to port %ld %s\n",
  48.         host>>24 & 0xff, host>>16 & 0xff, host>>8 & 0xff, host & 0xff,
  49.         dport, allow? "allowed": "denied");
  50.  
  51.       UNLOCK_NDB(NDB);
  52.       return allow;
  53. #undef allow
  54. #undef host
  55. #undef AT
  56.     }
  57.   /*
  58.    * No match. allow by default.
  59.    */
  60.   UNLOCK_NDB(NDB);
  61.   return ACF_ALLOW;
  62. }
  63.